package com.huangkailong.sqlprinter.boot;

import com.huangkailong.sqlprinter.boot.util.AnsiLog;
import com.huangkailong.sqlprinter.boot.util.ProcessUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author huangkailong
 * @since 1.0.0
 */
public class SqlPrinterBootMain {
    public static void main(String[] args) {
        long pid = ProcessUtils.select(false, -1, null);
        List<String> attachArgs = new ArrayList<String>();
        String libHome = "lib";
        attachArgs.add("-jar");
        attachArgs.add(new File(libHome, "sql-printer-core.jar").getAbsolutePath());
        attachArgs.add("-pid");
        attachArgs.add("" + pid);
        attachArgs.add("-agent");
        attachArgs.add(new File(libHome, "sql-printer-agent.jar").getAbsolutePath());
        AnsiLog.info("Try to attach process " + pid);
        AnsiLog.info("Start sql-printer-core.jar args: " + attachArgs);
        ProcessUtils.startArthasCore(pid, attachArgs);
        AnsiLog.info("Attach process {} success.", pid);
    }
}
